﻿using System.Diagnostics;
using System.IO;

namespace OpenLS.Spreadsheet.Formats.Biff.Records
{
    internal class DXFNumUsr : DXFNum
    {
        private XLUnicodeString fmt;
#if DEBUG
        private ushort lastCb;
#endif
        public override void Read(BinaryReader reader)
        {
#if DEBUG
            ReadWriteChecker.CheckClass((t, r) => t.Read(r), (t, w) => t.Write(w), reader, this);
#endif
            ushort cb = reader.ReadUInt16();
#if DEBUG
            lastCb = cb;
#endif
            Debug.WriteLine("Reading cb " + cb);
            fmt.Read(reader);
            Debug.WriteLine("Reading fmt " + (string)fmt);
        }

        public override void Write(BinaryWriter writer)
        {
            long position = writer.BaseStream.Position;
            writer.Write((ushort) 0);
            fmt.Write(writer);
            Debug.WriteLine("Writing fmt " + fmt);
            long newPosition = writer.BaseStream.Position;
            writer.BaseStream.Position = position;
            writer.Write((ushort) (newPosition - position));
            Debug.WriteLine("Writing cb " + (newPosition - position));
            writer.BaseStream.Position = newPosition;
        }

        public override InternalNumberFormat GetNumberFormat()
        {
            throw new System.NotImplementedException();
        }
    }
}